<template>
  <svg :class="svgClass" aria-hidden="true">
    <use :xlink:href="iconName" />
  </svg>
</template>

<script>
import { computed, defineComponent } from "vue";
export default defineComponent({
  props: {
    iconClass: {
      type: String,
      required: true,
    },
    className: {
      type: String,
      default: "",
    },
  },
  setup(props) {
    return {
      //拼接出入的svg文件名到iconName
      iconName: computed(() => `#icon-${props.iconClass}`),
      //将传入的class拼接到svgClass上
      svgClass: computed(() => {
        if (props.className) {
          return `svg-icon ${props.className}`;
        }
        return "svg-icon";
      }),
    };
  },
});
</script>
<style scope lang="scss">
.svg-icon {
  position: relative;
  fill: currentColor;
}
</style>
